<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const p = {
            firstName:'A',
            lastName:'B'
        }

        Object.defineProperty(p,'fullName',{
            get(){
                console.log('getter');
                return this.firstName+'-'+this.lastName
            },  
            set(value){
                console.log('setter');
                const names = value.split('-')
                this.firstName = names[0]
                this.lastName = names[1]
            }
        })

        console.log(p.fullName);
        p.fullName = 'e-f'
        console.log(p.firstName,p.lastName)

        p.firstName = 'c'
        p.lastName = 'd'
        console.log(p.fullName);

    </script>
</body>
</html>